<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
<title></title>
<%@ include file="/WEB-INF/jsp/common/inc.jsp" %>
<link rel="stylesheet" href="${_resources}bootstrap/bootstrap.min.css" />
<link rel="stylesheet" href="${_resources}bootstrap/bootstrap-table.min.css" />
<script type="text/javascript" src="${_resources}jquery-ui/jquery-ui-1.10.4.custom.min.js"></script>
<link rel="stylesheet" href="${_resources}jquery-ui/jquery-ui-1.10.4.custom.min.css" />
<link type="text/css" rel="stylesheet" href="${_resources}css/style.css">
<script  type="text/javascript">
	var documentList;
	var kdProjectId = '${kdProjectId}';
	$(function (){
		documentList = $("#documentList").bootstrapTable({
			url : '${_baseUrl}/kdtrUplodeDocController/getKdProjectDocList?number='+Math.random(),
			pagination: true,
			pageList: [5, 10, 20, 50],
	  		queryParams: queryParams,
	  		clickToSelect: false,
       	  	singleSelect  : true,
	  		columns: [{
	  	       	 field: 'radio',
	  	         radio: true,
	  	       	 title: '选择'
	  	     	},{
	            field: 'serial',
	            title: '序号',
	            width: 50,
	            formatter : function(value, row, index) {
	            	var str;
	            	if(status){
	            		str=value;
	            	}else{
	            		str=index+1;
	            	}
	 				return str;
	            }
	        },{
	           field: 'id',
	           title: 'id',
	           visible:false,
	           width: 5
	       },{
	            field: 'templateName',
	            title: '工作产品',
	            width: 100,
	            formatter : function(value, row, index) {
	            	return "<a onClick=\"showAllDocument('"+row.id+"','"+kdProjectId+"');\">"+value+"</a>";
	            }
	        },{
	            field: 'startTime',
	            title: '开始时间',
	            width: 100,
	            formatter : function(value, row, index) {
	            	if(value == null){
	            		return "--";
	            	}else{
	            	var v = value.substring(0,value.length-3);
	            	return v;
	            	}
	            }
	        },{
	            field: 'endTime',
	            title: '完成时间',
	            width: 110,
	            formatter : function(value, row, index) {
	            	if(value == null){
	            		return "--";
	            	}else{
	            		var v = value.substring(0,value.length-3);
		            	return v;
	            	}
	            }
	        },{
	            field: 'documentManagerName',
	            title: '文档负责人',
	            width: 95
	        },{
	            field: 'documentTeamPeopleName',
	            title: '协同编制人员',
	            width: 110
	        },{
	            field: 'documentVersion',
	            title: '文档版本',
	            width: 85
	        },{
	            field: '',
	            title: '历史版本',
	            width: 85,
	            formatter : function(value, row, index) {
	            	return "<a style=\"width:100%;\" onClick=\"loadDocumentHistoryVersions('"+row.id+"','"+row.templateId+"','"+row.projectId+"','"+row.documentStatus+"');\">查看</a>";
				}
	        },{
	            field: 'traceDocumentName',
	            title: '追踪文档',
	            width: 120
	        }],
	        onLoadSuccess : function(data) {
	        	var cellIndex=parseInt($(".table_inline th").length);
	            $(".table_inline tr td").each(function(){
	                if(this.cellIndex != cellIndex){
	                    $(this).attr("title",$(this).text());
	                }
	            });
	  		},
	    });
	});
		
		
	function queryParams(params){
       return {
            pageSize: params.limit,
            pageNo: params.pn,
            sort : params.sort,
            order : params.order,
            kdProjectId : kdProjectId,
            ktProjectId : parent.projectId
       };
    }

	function refreshTable(){
		documentList.bootstrapTable('refresh');
	}

	
	function cancel(){
		var index = parent.layer.getFrameIndex(window.name);
		parent.layer.close(index);
	}
	function save(){
		
		var selected = documentList.bootstrapTable('getSelections');
		if(selected.length == 0){
			layer.msg("请选择一个需要解析的文档");
			return false;
		}
		$("#submit").removeAttr("onclick");
		layer.confirm('正在上传数据,请稍后...',{icon: 16,shade: 0.3,
			success: function(layero){
	        	 var obj = $(".layui-layer"),oClose = $(".layui-layer-close");
				 str = "<iframe  frameborder=\"0\" scrolling=\"no\" style=\"position:absolute; background-color:transparent; width:100%; height:100%; top:0px; left:0px; z-index:-1;\"></iframe>";
				 obj.prepend(str);
				 oClose.click(function(){
					    var oShade = $("#templatelist").contents().find("#shade");
						oShade.css({'width':'0','height':'0'});
						$("#popDivs").css("height","100%");
			     }); 
			     $(".layui-layer").css("background-color","#f0efef");
					$(".layui-layer-content").css("text-align","center");
					$(".layui-layer-setwin").css("display","none");
					$(".layui-layer-btn").css("display","none");
					$(".layui-layer-title").css("display","none");
					$(".layui-layer-content").css("height","70px");
	        }});
		$.ajax({
			url : "${_baseUrl}/kdtrUplodeDocController/getDocContent",
			type : "post",
			dataType : "json",
			async : false,//** ！重要 同步请求。效果:ajax未进行则其他代码不运行
	  		data : { kdProjectId : kdProjectId,
	            ktProjectId : parent.projectId,
	            documentId : selected[0].id},
			success : function(json) {
				layer.msg(json.message,{shift:5,time:1000},function(){
					cancel();
					parent.refresh();
				});

			},
			error:function(data){
				layer.msg("系统错误,请联系管理员");
			}
		});
		
	}
	/* 关闭弹出框 */
	function closeWin(){
		layer.closeAll();
	}
	function loadDocumentHistoryVersions(id,templateId,projectId,status){
		layerIndex =layer.open({
		  type: 2, 
		  title:'文档版本信息',
		  area: ['900px', '400px'],
		  fixed: false, //不固定
		  maxmin: true,
		  content: "${_baseUrl}/document/loadDocumentHistoryVersions?templateId="+templateId+"&projectId="+projectId+"&documentId="+id+"&rand="+Math.random()
		});
		layer.full(layerIndex);
	}
	
   function showAllDocument(id,projectId){
	   layerIndex = layer.open({
			 type: 2,
			 title: '全文预览',
			 area: ['900px', '400px'],
			 fixed: false, //不固定
			 maxmin: true,
			 shim: true,
			 content:"${_baseUrl}/document/showAllDocument?documentId="+id+"&projectId="+projectId+"&rand="+Math.random()
			
		});	
	   layer.full(layerIndex);
	}
</script>
</head>
<style type="text/css">
.bootstrap-table{
width:100%;
}
</style>
<body>
	<div class="submenu">
	    <div class="dyi_list" id="1" >
	    	<div style="overflow: auto; width:98%;margin: auto;">
	        	<table class="table table-bordered table_inline" width="100%" border="0" cellspacing="0" cellpadding="0" id="documentList"></table>
	     	</div>
	    </div>
	</div>
	
<div class="submenu">
    <div class="func_bar">
    	<div class="btn_container" style="margin: 7px 0 5px 0px;">
		</div>
    </div>
    <div class="dyi_list" id="1" >
    <div style="overflow: auto; width:98%;margin: auto;">
        <table class="table table-bordered table_inline"   id="documentList">
    	</table>
    </div>
    <div class="important_Preservation">
	    <a href="javascript:void(0);" id="submit" onclick="save()">确定</a>
	    <a href="javascript:void(0);" id="cancel" onclick="cancel()">取 消</a>
	</div>
 </div>
 </div>	
</body>
</html>
